﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Workflow
{
    public partial class UpDownLoad : System.Web.UI.Page
    {
        private UpLoadManager objUpLoadManager = new UpLoadManager();
        public int workParentId;
        public string fileAddress;
        public List<WorkflowUpLoad> resultList = new List<WorkflowUpLoad>();
        protected void Page_Load(object sender, EventArgs e)
        {
            workParentId = Convert.ToInt32(Request.QueryString["WorkParentId"]);
            resultList = objUpLoadManager.GetUpLoadFile(workParentId);
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (file.PostedFile.ContentLength > 0)
                {
                    //workParentId = Convert.ToInt32(Request.QueryString["WorkParentId"]); 
                    fileAddress = fileAddress = @"\\vicosrv4\VS2008 Projects\WorkflowFiles\" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(file.PostedFile.FileName);
                    file.PostedFile.SaveAs(fileAddress);
                    string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(file.PostedFile.FileName);
                    objUpLoadManager.InsertUpLoadFile(workParentId, fileAddress,fileName);
                    string msg = string.Format("<script>alert('{0}');</script>", "上传成功");
                    //Response.Write(msg);
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
                }
            }
            catch (Exception ex)
            {

                string msg = string.Format("<script>alert('{0}')</script>", ex.Message);
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", msg);
            }
            finally
            {
                this.Page_Load(null, null);
            }
        }


    }
}